package com.lovely602.langchain4j.helloworld.controller;


import dev.langchain4j.model.chat.ChatModel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * 聊天控制器
 *
 * @author lizhixing
 */
@Slf4j
@RestController
@RequestMapping(value = "/chat")
public class ChatController {


    @Resource(name = "chatModelQwen")
    private ChatModel chatModelQwen;


    @Resource(name = "chatModelDeepSeek")
    private ChatModel chatModelDeepSeek;

    @GetMapping(value = "/qwen")
    public String qwen(@RequestParam(value = "msg", defaultValue = "你是谁", required = true) String msg) {
        String result = null;
        try {
            result = chatModelQwen.chat(msg);
        } catch (Exception e) {
            log.error("qwen error:", e);
        }

        return result;
    }

    @GetMapping(value = "/deepseek")
    public String deepSeek(@RequestParam(value = "msg", defaultValue = "你是谁", required = true) String msg) {
        String result = null;
        try {
            result = chatModelDeepSeek.chat(msg);
        } catch (Exception e) {
            log.error("qwen error:", e);
        }

        return result;
    }

}
